<?php
$mStudents = $this->maintenance;
$builder = $mStudents->builder;
$builder->db = $this->db;
$db = $this->db;

$tabs = $db->query_select('cllg_table_tab', "TABLE_NAME='cllg_student'");
$sql = sprintf("select * from cllg_student where ID='%s'", getParam('IDE'));
$rows = $db->queryToArray($sql, false);

$row = $rows[0];
$benef = $db->queryToArray(sprintf("select BENEFACTOR from
	cllg_student_benefactor where STUDENT=%s", getParam('IDE')));
if (count($benef) > 0) {
    $benef = $benef[0];
    $benef = $db->query_select('cllg_benefactor', sprintf("ID=%s", $benef["BENEFACTOR"]));
}
$idStud = $row['ID'];
$sqlPadre = "select a.ID,a.NOMBRE_A,a.APELLIDO_A from cllg_parent a,
	cllg_student_parent b where b.STUDENT=$idStud and a.ID=b.PARENT";
$padre = $db->queryToArray($sqlPadre, true);
if (count($padre) > 0) {
    $padre = $padre[0];
} else {
    $padre = array("ID" => "", "NOMBRE_A" => "", "APELLIDO_A" => "");
}


?>
<form id="<?php echo FORM_NAME; ?>" name="<?php echo FORM_NAME; ?>" method="post" action="<?php echo CORE_PATH; ?>" >
    <input type="hidden" id="module" name="module" value="<?php echo $this->instanceName; ?>" />
    <div id="mant_head" class="ui-widget-content ui-corner-all">
        <div id="titulo">Mantenimiento Alumnos</div>
        <div id="botones">
            <button id="cmdOk" type="button" onclick="doSubmit('operation=u')">
                <img alt=""  src="imgv2/actions/document-save.png" />
            </button>
            <button id="cmdCancel" type="button" onclick="doSubmit('')">
                <img alt=""  src="imgv2/actions/window-close.png" />
            </button>
        </div>
    </div>
    <div id="tabs">
        <ul>
            <li><a href="#tab1">INFORMACION PRINCIPAL</a></li>
            <?php
            $ix = 0;
            foreach ($tabs as $t) {
                $ix++;
                $tabId = "_tab_" . $ix;
                ?>
                <li ><a href="#<?php echo $tabId; ?>"><?php echo $t["CAPTION"]; ?></a></li>
            <?php } ?>
        </ul>
        <div class="form-container" id="tab1">
            <fieldset>
                <div>
                    <label for="ID"> * Identificaci&oacute;n</label>
                    <input  name="ID" value="<?php echo $row["ID"]; ?>" readonly="readonly" type="text" id="ID" />
                </div>
                <div>
                    <label for="FIRST_NAME"> * Nombres: </label>
                    <input name="FIRST_NAME" value="<?php echo $row["FIRST_NAME"]; ?>" type="text"  id="FIRST_NAME" size="60" maxlength="100" />
                </div>
                <div>
                    <label for="LAST_NAME"> * Apellidos:</label>
                    <input name="LAST_NAME"  type="text" id="LAST_NAME" size="60" maxlength="100" value="<?php echo $row["LAST_NAME"]; ?>" />
                </div>
                <div>
                    <label for="GENDER"> * Sexo:</label>
                    <select name="GENDER" size="1" id="GENDER">
                        <option value="M" <?php
            if (!(strcmp($row["GENDER"], "M"))) {
                echo "selected=\"selected\"";
            }
            ?>>Masculino</option>
                        <option value="F" <?php
                                if (!(strcmp($row["GENDER"], "F"))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Femenino</option>
                    </select>
                </div>
                <div>
                    <label for="BIRTH_DATE">Fecha de Nacimiento</label>
                    <input name="BIRTH_DATE"  type="text" id="BIRTH_DATE" value="<?php echo date("d/m/Y", strtotime($row["BIRTHDATE"])); ?>" />
                </div>
                <div>
                    <label for="EDAD">Edad</label>
                    <input name="EDAD" readonly="readonly"  type="text" id="EDAD" value="<?php echo date("Y") - date("Y", strtotime($row["BIRTHDATE"])); ?>" />
                </div>
                <div>
                    <label for="EMAIL">Correo Electr&oacute;nico</label>
                    <input name="EMAIL" type="text" id="EMAIL" value="<?php echo $row["EMAIL"]; ?>" />
                </div>
                <div>
                    <label for="STATUS">* Estado:</label>
                    <select name="STATUS" size="1" id="STATUS">
                        <option value="1" <?php
                                if (!(strcmp(1, $row['STATUS']))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Activo</option>
                        <option value="0" <?php
                                if (!(strcmp(0, $row['STATUS']))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Inactivo</option>
                    </select>
                </div>
                <div>
                    <label for="PICTUREPATH">*Fotografia:</label>
                    <div class="specialarea">
                        <div id="nuevafoto">
                            <?php if ($row['PICTURE_PATH'] != NULL) {
                                ?>
                                <img alt="foto"  width="200" height="200"
                                     src="<?php echo CORE_PATH . ModImages::$URL_IMAGES . strtoupper($row['PICTURE_PATH']) . ":80&" . AJAX_INDICATOR . "=true"; ?>" />
                                 <?php } ?>
                        </div>
                        <a id="cargarFoto"
                           href="<?php echo CORE_PATH; ?>?module=<?PHP echo ModUploader::$INSTANCE_NAME ?>&op=uploader&<?php echo AJAX_INDICATOR; ?>=true">Cambiar</a>
                        <input name="PICTURE_PATH" type="hidden" id="PICTURE_PATH" value="<?php echo $row['PICTURE_PATH']; ?>" />
                    </div>
                </div>
                <?php
                if (count($benef) > 0) {
                    $benef = $benef[0];
                    ?>
                    <div>
                        <label for="BENEF">Benefactor </label>
                        <input name="BENEFACTOR" readonly="readonly"  type="text" size="60" id="BENEFACTOR"
                               value="<?php echo $benef["ID"]; ?>-<?php echo $benef["RAZON_SOCIAL"]; ?>" />
                    </div>
                <?php } ?>
                <div>
                    <label for="PADRE">Padre de Familia</label>
                    <input name="PADRE" readonly="readonly"  type="text" size="80" id="PADRE"
                           value="<?php echo $padre["ID"] . " - " . $padre["NOMBRE_A"] . " " . $padre["APELLIDO_A"]; ?>" />
                </div>
            </fieldset>
            <div id="otrosdatos" style="height: 300px;">
                <div id="asignaciones" style="width:300px; float: left;">
                    <table id="asigns"></table>
                    <div id="pag"></div>
                    <script type="text/javascript" >
                        (function($){
                            var path=AJAX_CORE_URL+"_search=true&operation=listasig&ID="+$("#ID").val()
                            var cols=['CODIGO','GRADO'];
                            var model=[{name:'CODIGO',  index:'CODIGO' },{ name:'NOMBRE',  index:'NOMBRE'  }];
                            createGrid("#asigns","#pag",null,path,"Grados",true,cols,model);                                                                                          
                        })(jQuery)
                    </script>
                </div>
                <div id="cobrospendientes" style="margin-left: 5px; width:300px; float: left;">
                    <table id="pendientes"></table>
                    <div id="pagpend"></div>
                    <script type="text/javascript" >
                        (function($){
                            var path=AJAX_CORE_URL+"_search=true&operation=pendientes&ID="+$("#ID").val()
                            var cols=['DESCRIPCION','FECHA','VALOR'];
                            var model=[{name:'DESCRIPCION',  index:'DESCRIPCION' },
                                { name:'FECHA',  index:'FECHA'  },
                                { name:'VALOR',  index:'VALOR'  }];
                            createGrid("#pendientes","#pagpend",null,path,"Cobros Pendientes",true,cols,model);                                             
                        })(jQuery)
                    </script>
                </div>
            </div>
        </div>

        <?php
        $ix = 0;
        foreach ($tabs as $t) {
            $ix++;
            ?>
            <div class="form-container" id="_tab_<?php echo $ix; ?>">
                <fieldset>
                    <?php $builder->build("cllg_student", $row['ID'], $t['ID']); ?>
                </fieldset>
            </div>
        <?php } ?>
    </div>
</form>
<script type="text/javascript">
    jQuery("#tabs").tabs();
</script>